package com.esri.android.map;

import android.util.Log;
import com.esri.android.map.CSVLayer;
import com.esri.android.map.a;
import com.esri.android.map.ags.ArcGISDynamicMapServiceLayer;
import com.esri.android.map.ags.ArcGISFeatureLayer;
import com.esri.android.map.ags.ArcGISImageServiceLayer;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
import com.esri.android.map.bing.BingMapsLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.map.event.OnWebMapLoadListener;
import com.esri.android.map.ogc.KMLLayer;
import com.esri.android.map.ogc.WMSLayer;
import com.esri.android.map.ogc.WMTSLayer;
import com.esri.android.map.osm.OpenStreetMapLayer;
import com.esri.core.ags.LayerServiceInfo;
import com.esri.core.ags.MapServiceInfo;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.d;
import com.esri.core.internal.tasks.ags.t;
import com.esri.core.internal.tasks.ags.v;
import com.esri.core.internal.tasks.e.a.f;
import com.esri.core.internal.tasks.e.a.g;
import com.esri.core.internal.tasks.e.a.h;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.DynamicLayerInfo;
import com.esri.core.map.ImageServiceParameters;
import com.esri.core.map.LayerMapSource;
import com.esri.core.map.LayerSource;
import com.esri.core.map.popup.PopupInfo;
import com.esri.core.ogc.wmts.WMTSServiceInfo;
import com.esri.core.portal.Portal;
import com.esri.core.portal.WebMap;
import com.esri.core.portal.WebMapLayer;
import com.esri.core.portal.WebMapPopupInfo;
import com.esri.core.portal.WebMapSubLayer;
import com.sangfor.ssl.service.utils.IGeneral;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class b implements WebMapLayerLoader {
    private Set<WebMapLayer> a;
    private final WebMap c;
    private final MapView d;
    private final Portal e;
    private final boolean f;
    private final OnWebMapLoadListener g;
    private Map<Integer, com.esri.core.internal.map.a> i;
    private final d b = new d();
    private SpatialReference h = null;

    public b(WebMap webMap, MapView mapView, Portal portal, boolean z, OnWebMapLoadListener onWebMapLoadListener) {
        this.c = webMap;
        this.d = mapView;
        this.e = portal;
        this.f = z;
        this.g = onWebMapLoadListener;
    }

    public List<Layer> a(List<WebMapLayer> list) throws Exception {
        ArrayList arrayList = new ArrayList();
        if (list != null && !list.isEmpty()) {
            a(list, this.e);
            for (Map.Entry<WebMapLayer, Object> entry : b(list).entrySet()) {
                Object value = entry.getValue();
                if (value != null) {
                    Layer layer = null;
                    WebMapLayer key = entry.getKey();
                    if (value instanceof Future) {
                        Object obj = ((Future) value).get();
                        if (obj != null) {
                            a.C0012a<MapServiceInfo> c0012a = (a.C0012a) obj;
                            if (c0012a != null && (c0012a.a instanceof MapServiceInfo)) {
                                SpatialReference spatialReference = (this.h != null || c0012a.a == null || key == null || !key.mIsBaseLayer) ? this.h : c0012a.a.getSpatialReference();
                                this.h = spatialReference;
                                layer = a(key, c0012a, spatialReference);
                            } else if (c0012a != null && c0012a.a != null && (c0012a.a instanceof LayerServiceInfo)) {
                                LayerServiceInfo layerServiceInfo = (LayerServiceInfo) c0012a.a;
                                if ("Feature Layer".equals(layerServiceInfo.getType())) {
                                    layer = a(key, layerServiceInfo);
                                }
                            }
                        }
                    } else if (value instanceof KMLLayer) {
                        SpatialReference spatialReference2 = this.h;
                        if (spatialReference2 != null && spatialReference2.getID() != SpatialReference.WKID_WGS84) {
                            ((KMLLayer) value).setDefaultSpatialReference(SpatialReference.create(this.h.getID()));
                        }
                        layer = (Layer) value;
                        layer.b();
                    } else {
                        layer = (Layer) value;
                    }
                    if (layer != null) {
                        arrayList.add(layer);
                    }
                }
            }
        }
        return arrayList;
    }

    private void a(List<WebMapLayer> list, Portal portal) {
        if (portal == null || portal.getCredentials() == null) {
            return;
        }
        if (portal.getCredentials().getToken() == null) {
            try {
                portal.fetchPortalInfo();
            } catch (Exception unused) {
                return;
            }
        }
        for (WebMapLayer webMapLayer : list) {
            try {
                this.b.a(portal, webMapLayer);
            } catch (Exception e) {
                if (e instanceof InterruptedIOException) {
                    if (this.a == null) {
                        this.a = new HashSet();
                    }
                    this.a.add(webMapLayer);
                }
            }
        }
    }

    @Override // com.esri.android.map.WebMapLayerLoader
    public <T> a.C0012a<T> loadServiceInfo(com.esri.core.internal.tasks.d<T> dVar, Layer layer, WebMapLayer webMapLayer) throws Exception {
        return new com.esri.android.map.a(dVar, this.c, this.d, webMapLayer, new a()).call();
    }

    @Override // com.esri.android.map.WebMapLayerLoader
    public void invokeOnWebMapLoadListener(WebMapLayer webMapLayer, Layer layer, UserCredentials userCredentials) {
        if ((layer instanceof KMLLayer) && layer != this.d.getLayer(0)) {
            layer.setDefaultSpatialReference(this.d.getSpatialReference());
            layer.b();
        }
        OnWebMapLoadListener onWebMapLoadListener = this.g;
        if (onWebMapLoadListener != null) {
            onWebMapLoadListener.onWebMapLayerAdd(this.d, this.c, webMapLayer, layer, userCredentials);
        }
    }

    private Map<WebMapLayer, Object> b(List<WebMapLayer> list) {
        Set<WebMapLayer> set;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (WebMapLayer webMapLayer : list) {
            if (webMapLayer != null && ((set = this.a) == null || !set.contains(webMapLayer))) {
                String url = webMapLayer.getUrl();
                if (url == null) {
                    if (webMapLayer.getFeatureCollection() != null || webMapLayer.getType() == WebMapLayer.Type.FEATURE_COLLECTION) {
                        linkedHashMap.put(webMapLayer, c(webMapLayer));
                    }
                } else if (url.matches(".+/MapServer/?$")) {
                    try {
                        linkedHashMap.put(webMapLayer, this.d.a.i.b.submit(new com.esri.android.map.a(new t(url, this.b.a(url)), this.c, this.d, webMapLayer, new a())));
                    } catch (Exception e) {
                        Log.e(com.esri.core.internal.a.a, "Failed to load a map layer!", e);
                    }
                } else if (url.contains("/FeatureServer") || url.matches(".+/MapServer/\\d+.*")) {
                    linkedHashMap.put(webMapLayer, b(webMapLayer));
                } else if (url.contains("/ImageServer")) {
                    try {
                        linkedHashMap.put(webMapLayer, d(webMapLayer));
                    } catch (Exception unused) {
                    }
                } else if (url.startsWith("BingMaps")) {
                    linkedHashMap.put(webMapLayer, e(webMapLayer));
                } else if (url.startsWith("OpenStreetMap")) {
                    linkedHashMap.put(webMapLayer, f(webMapLayer));
                } else if (webMapLayer.getType() == WebMapLayer.Type.CSV) {
                    linkedHashMap.put(webMapLayer, h(webMapLayer));
                } else if (webMapLayer.getType() == WebMapLayer.Type.WMS) {
                    linkedHashMap.put(webMapLayer, i(webMapLayer));
                } else if (webMapLayer.getType() == WebMapLayer.Type.WMTS) {
                    linkedHashMap.put(webMapLayer, j(webMapLayer));
                } else if (webMapLayer.getType() == WebMapLayer.Type.KML) {
                    linkedHashMap.put(webMapLayer, g(webMapLayer));
                } else {
                    try {
                        linkedHashMap.put(webMapLayer, this.d.a.i.b.submit(new com.esri.android.map.a(new v(url, this.b.a(url)), this.c, this.d, webMapLayer, new a())));
                    } catch (Exception unused2) {
                        if (!webMapLayer.mIsBaseLayer) {
                            this.d.a(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_UNSUPPORTED_LAYER));
                        } else {
                            MapView mapView = this.d;
                            mapView.a(new UnsupportedOperationException("WebMap.Layer: " + url));
                        }
                    }
                }
            }
        }
        return linkedHashMap;
    }

    private Layer a(WebMapLayer webMapLayer, a.C0012a<MapServiceInfo> c0012a, SpatialReference spatialReference) throws Exception {
        Layer layer;
        MapServiceInfo mapServiceInfo = c0012a.a;
        UserCredentials userCredentials = c0012a.b;
        if (mapServiceInfo.getTileInfo() != null && (spatialReference == null || com.esri.core.internal.util.d.a(spatialReference, mapServiceInfo.getSpatialReference()))) {
            layer = new ArcGISTiledMapServiceLayer(webMapLayer.getUrl(), userCredentials, false);
        } else {
            ArcGISDynamicMapServiceLayer arcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(webMapLayer.getUrl(), a(webMapLayer), webMapLayer.getInvisibleLegendLayers(), userCredentials, false);
            layer = arcGISDynamicMapServiceLayer;
            if (webMapLayer.getLayers() != null) {
                layer = arcGISDynamicMapServiceLayer;
                if (webMapLayer.getLayers().size() > 0) {
                    HashMap hashMap = new HashMap();
                    ArrayList arrayList = new ArrayList();
                    for (WebMapSubLayer webMapSubLayer : webMapLayer.getLayers()) {
                        com.esri.core.internal.map.a a2 = a(webMapSubLayer.getLayerId(), webMapSubLayer.getLayerDefinition());
                        int a3 = a(webMapSubLayer);
                        if (a2 != null) {
                            if (a2.k() != null) {
                                hashMap.put(Integer.valueOf(a3), a2.k());
                            }
                            arrayList.add(new DynamicLayerInfo(a3, a2.b(), a2.l()));
                        }
                    }
                    arcGISDynamicMapServiceLayer.setLayerDefinitions(hashMap);
                    arcGISDynamicMapServiceLayer.setDynamicLayerInfos(arrayList);
                    layer = arcGISDynamicMapServiceLayer;
                }
            }
        }
        layer.a(mapServiceInfo);
        return a(webMapLayer, layer);
    }

    private int[] a(WebMapLayer webMapLayer) {
        int[] visibleLayers = webMapLayer.getVisibleLayers();
        if (webMapLayer.getLayers() != null && !webMapLayer.getLayers().isEmpty()) {
            for (WebMapSubLayer webMapSubLayer : webMapLayer.getLayers()) {
                com.esri.core.internal.map.a a2 = a(webMapSubLayer.getLayerId(), webMapSubLayer.getLayerDefinition());
                if (a2 != null && a2.l() != null && a2.l().getType() == LayerSource.LayerType.MAPLAYER) {
                    int i = 0;
                    while (true) {
                        if (i >= visibleLayers.length) {
                            break;
                        } else if (visibleLayers[i] == webMapSubLayer.getLayerId()) {
                            visibleLayers[i] = ((LayerMapSource) a2.l()).getLayerId();
                            break;
                        } else {
                            i++;
                        }
                    }
                }
            }
        }
        return visibleLayers;
    }

    private Layer b(WebMapLayer webMapLayer) throws Exception {
        return a(webMapLayer, (LayerServiceInfo) null);
    }

    private Layer a(WebMapLayer webMapLayer, LayerServiceInfo layerServiceInfo) throws Exception {
        ArcGISFeatureLayer arcGISFeatureLayer = new ArcGISFeatureLayer(webMapLayer.getUrl(), webMapLayer.getLayerDefinitionOverride(), webMapLayer.getMode() == null ? null : ArcGISFeatureLayer.MODE.valueOf(webMapLayer.getMode().toString()), false, this.b.a(webMapLayer.getUrl()));
        String capabilitiesOverride = webMapLayer.getCapabilitiesOverride();
        if (layerServiceInfo != null) {
            arcGISFeatureLayer.a(layerServiceInfo);
            if (capabilitiesOverride != null && capabilitiesOverride.length() > 0) {
                layerServiceInfo.setCapabilities(capabilitiesOverride);
            }
        } else if (capabilitiesOverride != null && capabilitiesOverride.length() > 0) {
            arcGISFeatureLayer.a((Object) capabilitiesOverride);
        }
        return a(webMapLayer, arcGISFeatureLayer);
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x006a  */
    /* JADX WARN: Removed duplicated region for block: B:74:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r0v6, types: [int] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private com.esri.android.map.GroupLayer c(com.esri.core.portal.WebMapLayer r14) {
        /*
            Method dump skipped, instructions count: 275
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.b.c(com.esri.core.portal.WebMapLayer):com.esri.android.map.GroupLayer");
    }

    private Layer d(WebMapLayer webMapLayer) throws Exception {
        ImageServiceParameters imageServiceParameters = new ImageServiceParameters();
        imageServiceParameters.setBandIds(webMapLayer.getBandIds());
        imageServiceParameters.setRenderingRule(webMapLayer.getRenderingRule());
        imageServiceParameters.setMosaicRule(webMapLayer.getMosaicRule());
        imageServiceParameters.setFormat(webMapLayer.getImageFormat());
        imageServiceParameters.setCompressionQuality(webMapLayer.getImageCompressionQuality());
        imageServiceParameters.setInterpolation(webMapLayer.getImageInterpolation());
        imageServiceParameters.setNoData(webMapLayer.getImageNoDataPixelValue());
        imageServiceParameters.setNoDataInterpretation(webMapLayer.getImageNoDataInterpretation());
        ArcGISImageServiceLayer arcGISImageServiceLayer = new ArcGISImageServiceLayer(webMapLayer.getUrl(), imageServiceParameters, this.b.a(webMapLayer.getUrl()), false);
        arcGISImageServiceLayer.setLayerDefinitionOverride(webMapLayer.getLayerDefinitionOverride());
        return a(webMapLayer, arcGISImageServiceLayer);
    }

    private Layer e(WebMapLayer webMapLayer) {
        String str = this.d.m;
        if (str == null || str.trim().equals("")) {
            try {
                String portalUrl = webMapLayer.getPortalUrl();
                if (portalUrl != null) {
                    if (portalUrl.contains("/sharing")) {
                        portalUrl = portalUrl.substring(0, portalUrl.indexOf("/sharing"));
                    }
                    WebMap webMap = this.c;
                    str = new Portal(portalUrl, a(portalUrl, webMap != null ? webMap.getInfo().getPortal().getUrl() : null) ? this.c.getCredentials() : null).fetchPortalInfo().getBingKey();
                }
            } catch (Exception e) {
                Log.e(com.esri.core.internal.a.a, "", e);
            }
            if (str == null || str.trim().equals("")) {
                Log.e(com.esri.core.internal.a.a, "Missing AppId:", new UnsupportedOperationException("A Bing Maps layer cannot be created if no appID is provided. Please provide a valid appID."));
                if (this.f) {
                    this.d.a(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_BING_LAYER));
                } else {
                    OnWebMapLoadListener onWebMapLoadListener = this.g;
                    if (onWebMapLoadListener != null) {
                        onWebMapLoadListener.onWebMapLoadError(this.d, this.c, webMapLayer, null, new OnStatusChangedListener.EsriStatusException(OnStatusChangedListener.EsriStatusException.INIT_FAILED_BING_LAYER), null);
                    }
                }
                return null;
            }
        }
        return a(webMapLayer, new BingMapsLayer(str, BingMapsLayer.MapStyle.fromString(webMapLayer.getUrl().replaceFirst("BingMaps", "")), false));
    }

    private Layer f(WebMapLayer webMapLayer) {
        return a(webMapLayer, new OpenStreetMapLayer(false));
    }

    private Layer g(WebMapLayer webMapLayer) {
        KMLLayer kMLLayer = new KMLLayer(webMapLayer.getUrl(), SpatialReference.create(SpatialReference.WKID_WGS84), false);
        kMLLayer.a(webMapLayer.getTitle());
        kMLLayer.a(this, webMapLayer);
        int[] visibleFolders = webMapLayer.getVisibleFolders();
        if (visibleFolders != null && visibleFolders.length > 0) {
            ArrayList arrayList = new ArrayList();
            for (int i : visibleFolders) {
                arrayList.add(new Integer(i));
            }
            kMLLayer.a(arrayList);
        }
        kMLLayer.setOpacity(webMapLayer.getOpacity());
        kMLLayer.setVisible(webMapLayer.isVisible());
        kMLLayer.setMinScale(webMapLayer.getMinScale());
        kMLLayer.setMaxScale(webMapLayer.getMaxScale());
        return kMLLayer;
    }

    private Layer h(WebMapLayer webMapLayer) {
        String layerDefinitionOverride = webMapLayer.getLayerDefinitionOverride();
        CSVLayer.CSVConfig cSVConfig = new CSVLayer.CSVConfig();
        cSVConfig.columnDelimiter = webMapLayer.getColumnDelimiter();
        cSVConfig.url = webMapLayer.getUrl();
        cSVConfig.latitudeField = webMapLayer.getLatitudeFieldName();
        cSVConfig.longitudeField = webMapLayer.getLongitudeFieldName();
        return a(webMapLayer, new CSVLayer(layerDefinitionOverride, cSVConfig, false));
    }

    private Layer i(WebMapLayer webMapLayer) {
        f fVar = new f();
        fVar.b(webMapLayer.getWmsVersion());
        fVar.a(webMapLayer.getMapUrl());
        g gVar = new g();
        if (webMapLayer.getWmsVersion().equals(f.d)) {
            gVar.a(g.a);
        } else {
            gVar.a(g.b);
        }
        gVar.a(webMapLayer.getExtent());
        fVar.a(gVar);
        if (webMapLayer.getSpatialRefs() != null && webMapLayer.getSpatialRefs().size() > 0) {
            ArrayList arrayList = new ArrayList();
            Iterator<SpatialReference> it = webMapLayer.getSpatialRefs().iterator();
            while (it.hasNext()) {
                arrayList.add("EPSG:" + it.next().getID());
            }
            fVar.a(arrayList);
        }
        if (webMapLayer.getLayers() != null && webMapLayer.getLayers().size() > 0) {
            ArrayList arrayList2 = new ArrayList();
            for (WebMapSubLayer webMapSubLayer : webMapLayer.getLayers()) {
                h hVar = new h();
                hVar.a(webMapSubLayer.getName());
                hVar.b(webMapSubLayer.getTitle());
                hVar.c(webMapSubLayer.getLegendURL());
                arrayList2.add(hVar);
            }
            fVar.b(arrayList2);
        }
        Layer wMSLayer = new WMSLayer(webMapLayer.getUrl(), null, true, webMapLayer.getWmsVisibleLayers() != null ? (String[]) webMapLayer.getWmsVisibleLayers().toArray(new String[0]) : null, null, false);
        wMSLayer.a(fVar);
        return a(webMapLayer, wMSLayer);
    }

    private Layer j(WebMapLayer webMapLayer) {
        return a(webMapLayer, new WMTSLayer(new WMTSServiceInfo(webMapLayer).getLayerInfos().get(0), webMapLayer.getTileInfo().getSpatialReference(), webMapLayer.getWmtsTemplateUrl()));
    }

    private com.esri.core.internal.map.a a(int i, String str) {
        com.esri.core.internal.map.a aVar;
        Exception e;
        com.esri.core.internal.map.a aVar2;
        JsonParser c;
        Map<Integer, com.esri.core.internal.map.a> map = this.i;
        if (map == null) {
            this.i = new HashMap();
            aVar = null;
        } else {
            aVar = map.get(Integer.valueOf(i));
        }
        if (aVar != null || str == null) {
            return aVar;
        }
        try {
            c = com.esri.core.internal.util.d.c(str);
        } catch (Exception e2) {
            com.esri.core.internal.map.a aVar3 = aVar;
            e = e2;
            aVar2 = aVar3;
        }
        if (c != null) {
            c.nextToken();
            if (c.getCurrentToken() == JsonToken.START_OBJECT) {
                aVar2 = com.esri.core.internal.map.a.a(c);
                try {
                    this.i.put(Integer.valueOf(i), aVar2);
                } catch (Exception e3) {
                    e = e3;
                    Log.i(com.esri.core.internal.a.a, "Failed to parse the layer definition for layer :" + i, e);
                    return aVar2;
                }
                return aVar2;
            }
            return aVar;
        }
        return aVar;
    }

    private int a(WebMapSubLayer webMapSubLayer) {
        com.esri.core.internal.map.a aVar;
        LayerSource l;
        if (webMapSubLayer == null) {
            return -1;
        }
        Map<Integer, com.esri.core.internal.map.a> map = this.i;
        if (map != null && !map.isEmpty() && (aVar = this.i.get(Integer.valueOf(webMapSubLayer.getLayerId()))) != null && (l = aVar.l()) != null && (l instanceof LayerMapSource)) {
            return ((LayerMapSource) l).getLayerId();
        }
        return webMapSubLayer.getLayerId();
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x00e7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private com.esri.android.map.Layer a(com.esri.core.portal.WebMapLayer r8, com.esri.android.map.Layer r9) {
        /*
            r7 = this;
            if (r8 == 0) goto L10e
            java.lang.String r0 = r8.getTitle()
            r9.a(r0)
            boolean r0 = r8.isVisible()
            r1 = 0
            if (r0 != 0) goto L13
            r9.setVisible(r1)
        L13:
            java.util.List r0 = r8.getLayers()
            r2 = 0
            if (r0 == 0) goto L94
            java.util.List r0 = r8.getLayers()
            boolean r0 = r0.isEmpty()
            if (r0 != 0) goto Le0
            java.util.HashMap r2 = new java.util.HashMap
            r2.<init>()
            java.util.HashMap r0 = new java.util.HashMap
            r0.<init>()
            java.util.List r1 = r8.getLayers()
            java.util.Iterator r1 = r1.iterator()
        L36:
            boolean r3 = r1.hasNext()
            if (r3 == 0) goto Le1
            java.lang.Object r3 = r1.next()
            com.esri.core.portal.WebMapSubLayer r3 = (com.esri.core.portal.WebMapSubLayer) r3
            int r4 = r7.a(r3)
            com.esri.core.portal.WebMapPopupInfo r5 = r3.getWebMapPopupInfo()
            if (r5 == 0) goto L66
            com.esri.core.portal.WebMapPopupInfo r5 = r3.getWebMapPopupInfo()
            r7.a(r5, r8, r4)
            com.esri.android.map.ags.ArcGISPopupInfo r5 = new com.esri.android.map.ags.ArcGISPopupInfo
            com.esri.core.portal.WebMapPopupInfo r6 = r3.getWebMapPopupInfo()
            r5.<init>(r6)
            r7.a(r5, r8)
            java.lang.Integer r6 = java.lang.Integer.valueOf(r4)
            r2.put(r6, r5)
        L66:
            java.lang.String r5 = r3.getLayerURL()
            if (r5 != 0) goto L86
            java.lang.StringBuilder r3 = new java.lang.StringBuilder
            java.lang.String r5 = r8.getUrl()
            r3.<init>(r5)
            java.lang.String r5 = "/"
            r3.append(r5)
            java.lang.String r5 = java.lang.String.valueOf(r4)
            r3.append(r5)
            java.lang.String r3 = r3.toString()
            goto L8a
        L86:
            java.lang.String r3 = r3.getLayerURL()
        L8a:
            if (r3 == 0) goto L36
            java.lang.Integer r4 = java.lang.Integer.valueOf(r4)
            r0.put(r4, r3)
            goto L36
        L94:
            com.esri.core.portal.WebMapPopupInfo r0 = r8.getWebMapPopupInfo()
            if (r0 == 0) goto Le0
            java.util.HashMap r2 = new java.util.HashMap
            r2.<init>()
            java.util.HashMap r3 = new java.util.HashMap
            r3.<init>()
            com.esri.android.map.ags.ArcGISPopupInfo r4 = new com.esri.android.map.ags.ArcGISPopupInfo
            r4.<init>(r0)
            r7.a(r4, r8)
            java.lang.Integer r5 = java.lang.Integer.valueOf(r1)
            r2.put(r5, r4)
            java.lang.String r4 = r0.getLayerUrl()
            if (r4 == 0) goto Ld3
            java.lang.String r4 = r0.getLayerUrl()
            java.lang.String r4 = r4.trim()
            int r4 = r4.length()
            if (r4 <= 0) goto Ld3
            java.lang.Integer r1 = java.lang.Integer.valueOf(r1)
            java.lang.String r0 = r0.getLayerUrl()
            r3.put(r1, r0)
            goto Lde
        Ld3:
            java.lang.Integer r0 = java.lang.Integer.valueOf(r1)
            java.lang.String r1 = r8.getUrl()
            r3.put(r0, r1)
        Lde:
            r0 = r3
            goto Le1
        Le0:
            r0 = r2
        Le1:
            boolean r1 = r8.isDisablePopup()
            if (r1 != 0) goto Lea
            r9.setPopupInfos(r2)
        Lea:
            r9.setQueryUrls(r0)
            double r0 = r8.getMinScale()
            r9.setMinScale(r0)
            double r0 = r8.getMaxScale()
            r9.setMaxScale(r0)
            float r0 = r8.getOpacity()
            r9.setOpacity(r0)
            boolean r0 = r8.mIsBaseLayer
            r9.a(r0)
            boolean r0 = r8.isShowLegend()
            r9.b(r0)
        L10e:
            com.esri.core.portal.WebMap r0 = r7.c
            if (r0 == 0) goto L119
            com.esri.core.geometry.Envelope r0 = r0.getInitExtent()
            r9.setInitialExtent(r0)
        L119:
            r9.a(r7, r8)
            r9.b()
            return r9
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.b.a(com.esri.core.portal.WebMapLayer, com.esri.android.map.Layer):com.esri.android.map.Layer");
    }

    private void a(PopupInfo popupInfo, WebMapLayer webMapLayer) {
        popupInfo.setMinScale(webMapLayer.getMinScale());
        popupInfo.setMaxScale(webMapLayer.getMaxScale());
    }

    private void a(WebMapPopupInfo webMapPopupInfo, WebMapLayer webMapLayer, int i) {
        if (webMapPopupInfo.getLayerUrl().endsWith(String.valueOf(i))) {
            return;
        }
        webMapPopupInfo.setLayerUrl(webMapLayer.getUrl() + "/" + i);
    }

    private boolean a(String str, String str2) {
        return a(str).equalsIgnoreCase(a(str2));
    }

    private String a(String str) {
        if (str != null) {
            if (str.startsWith(IGeneral.PROTO_HTTPS_HEAD)) {
                return str.substring(7);
            }
            return str.substring(6);
        }
        return str;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public class a implements OnWebMapLoadListener {
        boolean a;
        UserCredentials b;

        private a() {
            this.a = false;
            this.b = null;
        }

        /* JADX WARN: Removed duplicated region for block: B:16:0x002e  */
        @Override // com.esri.android.map.event.OnWebMapLoadListener
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct code enable 'Show inconsistent code' option in preferences
        */
        public com.esri.android.map.event.MapLoadAction<com.esri.core.io.UserCredentials> onWebMapLoadError(com.esri.android.map.MapView r14, com.esri.core.portal.WebMap r15, com.esri.core.portal.WebMapLayer r16, com.esri.android.map.Layer r17, java.lang.Throwable r18, com.esri.core.io.UserCredentials r19) {
            /*
                Method dump skipped, instructions count: 299
                To view this dump change 'Code comments level' option to 'DEBUG'
            */
            throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.b.a.onWebMapLoadError(com.esri.android.map.MapView, com.esri.core.portal.WebMap, com.esri.core.portal.WebMapLayer, com.esri.android.map.Layer, java.lang.Throwable, com.esri.core.io.UserCredentials):com.esri.android.map.event.MapLoadAction");
        }

        @Override // com.esri.android.map.event.OnWebMapLoadListener
        public void onWebMapLayerAdd(MapView mapView, WebMap webMap, WebMapLayer webMapLayer, Layer layer, UserCredentials userCredentials) {
            if (b.this.g != null) {
                b.this.g.onWebMapLayerAdd(mapView, webMap, webMapLayer, layer, userCredentials);
            }
        }
    }
}
